<template>
    <view class="content">

        <!--产品，供应商列表 -->
        <SupplierTow
            ref="SupplierTow"
            @setGoodsThree="setGoodsThree"
            @setSuppmInfo="setSuppmInfo"
            @addSupplier="addSupplier"
            @upDownClick="upDownClick"
        ></SupplierTow>

        <!-- 供应商详情页面 -->
        <SupplierThree
            ref="SupplierThree"
            v-show="curIndex == 1"
            @removeCustom="removeCustom"
            @bill="bill"
            @editSupplier="editSupplier"
            @updataCustomList="updataCustomList"
        >
        </SupplierThree>

        <!-- 添加/编辑供应商 -->
        <SupplierAdd
            ref="SupplierAdd"
            v-show="curIndex == 2"
            :actType="actType"
            @addCustomSuccess="addCustomSuccess"
        >
        </SupplierAdd>

        <!-- 导入供应商窗口 -->
        <ImportCustomers ref="ImportCustomers"></ImportCustomers>

        <!-- 上传下载菜单 -->
        <upAndDownLoadMenu
            ref="upAndDownLoadMenu"
            :md="mdKh"
            @showUploadCustomWin="showUploadCustomWin"
        ></upAndDownLoadMenu>
    </view>
</template>

<script>
import staticConst from "../../js/const/StaticConst.js";
import eventCtrl from "../../js/event/EventCtrl.js";
import supplierCtrl from "../../js/supplier/SupplierCtrl.js";
import upAndDownLoadMenu from "../../components/comm/UpAndDownLoadMenu.vue";

import ImportCustomers from "@/components/supplier/ImportCustomers.vue";
import SupplierAdd from "@/components/supplier/SupplierAdd.vue";
import SupplierTow from "@/components/supplier/SupplierTow.vue";
import SupplierThree from "@/components/supplier/SupplierThree.vue";
export default {
    components: {
        SupplierTow,
        SupplierThree,
        upAndDownLoadMenu,
        ImportCustomers,
        SupplierAdd,
    },
    data() {
        return {
            curPage: staticConst.CG_GYS,
            actType: 0, // 0:新增供应商 1：编辑编辑
            isNotData: false, // 没有数据
            mdKh: staticConst.CG_GYS, //模块
            curIndex: 1, //1,
        };
    },

    onLoad() {
	},

    onShow() {},

    onHide() {},

    onUnload() {},

    onReady() {
        if (supplierCtrl.addSupplier == 1) {
            supplierCtrl.addSupplier = 0; //用完，重置
            this.addSupplier();
        } else {
            this.$refs.SupplierTow.initData();
        }
    },

    methods: {
        /****显示上传产品列表窗口****/
        showUploadCustomWin() {
            this.$refs.ImportCustomers.show("show");
        },

        /*****显示上传下载菜单****/
        upDownClick() {
            this.isClickUpDownBtn = true;
            this.$refs.upAndDownLoadMenu.show();
        },

        /***点击产品列表处理**/
        setGoodsThree(data) {
            // this.$refs.receiptInfo.addGoodsReceipt(data);
        },

        /****选中供应商******/
        setSuppmInfo(data) {
            // this.$refs.receiptInfo.getCustomInfo(data,isCheckOut);
            this.curIndex = 1;
            this.$refs.SupplierThree.loadsuppinfo(data);
        },

        /****删除供应商*****/
        removeCustom(id) {
            this.$refs.SupplierTow.removeCustom(id);
        },

        /****开单操作****/
        bill(data) {
            supplierCtrl.setBillSupp(data);
			uni.$emit('write_bill',2);
        },

        /****添加供应商****/
        addSupplier() {
            this.curIndex = 2;
            this.actType = 0;
            this.$refs.SupplierAdd.init();
        },

        /****编辑供应商****/
        editSupplier(data) {
            this.curIndex = 2;
            this.actType = 1;
            this.$refs.SupplierAdd.init(data);
        },

        /*******添加修改供应商成功*******/
        addCustomSuccess(data) {
			console.log('=======================>',data);
            this.curIndex = 1;
            if (data.act == 0) {
                //新增供应商详情
                this.$refs.SupplierTow.addNewCustomer();
            } //编辑供应商详情
            else {
                this.$refs.SupplierThree.editsuppinfo(data.id);
            }
        },

        /***编辑供应商更新供应商****/
        updataCustomList(data) {
            this.$refs.SupplierTow.updataCustomList(data);
        },
    },
};
</script>
<style lang="scss">
.content {
    display: flex;
    justify-content: flex-start;
    min-width: 820px;
    height: 100%;
    position: relative;
}
</style>
